<?php

namespace App\Http\Controllers\Faculty;

use App\Common\Utils\JsonResponse;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class CreditController extends Controller
{
    /** @var \App\Services\System\LogService $logService */
    private $logService;
    /** @var \App\Services\Faculty\CreditService $creditService */
    private $creditService;

    /**
    * Create a new controller instance.
    *
    * @return void
    */
    public function __construct()
    {
        parent::__construct();
        $this->middleware('auth');
        $this->logService = app('logService');
        $this->creditService = app('creditService');
    }

    /**
     * @Description: 获取学分培训列表信息数据
     * @Author: kzj
     * @datetime: 2023-02-21
     */
    public function getList(Request $request)
    {
        try
        {
            $result = $this->creditService->getList($request->all());
            $this->logService->log('287', '学分培训查看', '学分培训查看');
            return JsonResponse::get($result['data'], TRUE, $result['total'], $result['per_page']);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * @Description: 学分培训单条数据
     * @Author: kzj
     * @datetime: 2023-02-28
     */
    public function one(Request $request)
    {
        try{
            $result = $this->creditService->one($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 学分培训数据导出
     * @Author: kzj
     * @datetime: 2023-02-28
     */
    public function export(Request $request)
    {
        try{
            $result = $this->creditService->export($request->all());
            $this->logService->log('348', '学分培训导出', '学分培训导出');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }
}
